<?php
/**
 * This file is part of the Jindai.
 * @copyright Copyright (c) 2019 Jindai.
 * @author jindai <jindai0305@gmail.com>
 */

namespace App\Http\Resources;

use App\Traits\ResourceTrait;
use Illuminate\Http\Resources\Json\JsonResource;

/**
 * Class SongMenu
 * @package App\Http\SongMenu
 *
 * @mixin \App\Models\SongMenu
 */
class SongMenu extends JsonResource
{
    use ResourceTrait;

    /**
     * @param $request
     * @return array
     *
     * @SWG\Definition(
     *     definition="songMenuDefault",
     *     type="object",
     *     @SWG\Property(property="id", type="integer", description="id", example=1),
     *     @SWG\Property(property="name", type="string", description="标题", example="计算机网络"),
     *     @SWG\Property(property="tags", type="object", description="图片",
     *          @SWG\Property(property="id", type="integer", description="主键id", example=1),
     *          @SWG\Property(property="url", type="string", description="跳转链接", example="https://www.w3school.com.cn//i/eg_tulip.jpg")
     *     ),
     *     @SWG\Property(property="created_at", type="integer", description="创建时间", example=1569292862),
     *     @SWG\Property(property="deleted_at", type="integer", description="删除时间", example=1569292862),
     * )
     */
    protected function toDefault($request)
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'tags' => $this->tags,
            'content' => $this->content,
            'cover' => $this->cover,
            'status' => $this->status,
            'created_at' => $this->created_at,
            'deleted_at' => $this->deleted_at,
            'is_default' => $this->isDefault()
        ];
    }

    /**
     * 编辑详情
     *
     * @param $request
     * @return array
     */
    protected function toEdit($request)
    {
        return array_merge($this->toDefault($request), [
            'songs' => $this->resourceInstance(SongCollection::class, $this->songs)->setStamp('menuEdit'),
        ]);
    }

    /**
     * @param $request
     * @return SongMenu
     */
    protected function toPlayer($request)
    {
        return $this->resourceInstance(SongCollection::class, $this->songs)->setStamp('menuEdit');
    }

    /**
     * @param $request
     * @return array
     *
     * @SWG\Definition(
     *     definition="songMenuIndex",
     *     type="object",
     *     allOf = {
     *          @SWG\Schema(ref="#/definitions/songMenuDefault"),
     *          @SWG\Schema(
     *          )
     *     }
     * )
     */
    protected function toIndex($request)
    {
        return array_merge($this->toDefault($request), [
        ]);
    }

    /**
     * @param $request
     * @return array
     *
     * @SWG\Definition(
     *     definition="songMenuView",
     *     type="object",
     *     allOf = {
     *          @SWG\Schema(ref="#/definitions/songMenuDefault"),
     *          @SWG\Schema(
     *          )
     *     }
     * )
     */
    protected function toView($request)
    {
        return array_merge($this->toDefault($request), [
        ]);
    }
}
